package com.neusoft.elm.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DBUtil {
	public static final String DIRVER = "com.mysql.jdbc.Driver";
	public static final String URL = "jdbc:mysql://127.0.0.1:3306/elm_admin?characterEncoding=utf-8&useSSL=false";
	public static final String USERNAME = "root";
	public static final String PASSWORD = "1234";
	
//	
	public static Connection getConnection(){
		Connection con = null;
		
		try {
//			
			Class.forName(DIRVER);
//			
			con = DriverManager.getConnection(URL,USERNAME,PASSWORD);
		} catch (ClassNotFoundException | SQLException e) {
			e.printStackTrace();
		} 
		return con;
	}
	
	public static void closeAll(ResultSet rs , PreparedStatement pst , Connection con){
		try {
			if(rs != null){
				rs.close();
			}
			if(pst != null){
				pst.close();
			}
			if(con != null){
				con.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
}
